package com.newcoder.community.controller;

import com.github.pagehelper.PageInfo;
import com.newcoder.community.entity.DiscussPost;
import com.newcoder.community.entity.User;
import com.newcoder.community.service.DiscussPostService;
import com.newcoder.community.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class HomeController {

    @Autowired
    DiscussPostService discussPostService;

    @Autowired
    UserService userService;

    @RequestMapping("/index")
    public String getIndexPage(@RequestParam(value = "currentPage", defaultValue = "1") int currentPage,
                               @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                               @RequestParam(value = "pageNum", defaultValue = "5", required = false) int pageNum,
                               Model model){
        List<DiscussPost> discussPosts = discussPostService.findDiscussPost(0, currentPage, pageSize);
        PageInfo<DiscussPost> pageInfo = new PageInfo<>(discussPosts, pageNum);
        model.addAttribute("pageInfo", pageInfo);
        System.out.println("你好啊");
        return "index";
    }
}
